﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KeRui.Common;


public partial class Aspx_AdHandle : System.Web.UI.Page
{
  
    private ManageErrMsg nsb = new ManageErrMsg();
    private KeRui.BLL.Ad bllAd = new KeRui.BLL.Ad();
    private KeRui.Model.Ad modelAd = new KeRui.Model.Ad();
    protected void Page_Load(object sender, EventArgs e)
    {
        string url = PageRequest.GetString("url").Trim();

        if (url == "")
        {
            url = "#";
        }

        int AdID = PageRequest.GetInt("ID", -1);
        if (AdID == -1)
        {
            nsb.AddErr("错误访问！"); nsb.ChkErr();
        }
        else
        {
            try
            {
                modelAd = bllAd.GetModel(AdID);
                if (modelAd == null)
                {
                    //nsb.AddErr("广告不存在！"); nsb.ChkErr();
                    Response.Redirect(url, false);
                }
                else
                {
                    KeRui.BLL.AdClick bllAdClick = new KeRui.BLL.AdClick();
                    KeRui.Model.AdClick modelAdClick = new KeRui.Model.AdClick();
                    modelAdClick.AdID = modelAd.AdID;
                    modelAdClick.SellerADID = modelAd.CurID;
                    modelAdClick.CreateIP = Utils.GetRealIP();
                    if (bllAdClick.Add(modelAdClick) > 0)
                    {
                        //Response.Write("<script> self.location.href='" + modelAd.CurUrl + "'</script>"); Response.End();
                        Response.Redirect(modelAd.CurUrl.Trim(), false);
                    }
                    else
                    {
                        nsb.AddErr("系统出现错误。"); nsb.ChkErr();
                    }
                }
            }
            catch( Exception ee)
            {
                //Response.Write("<script> self.location.href='" + url + "'</script>"); Response.End();
                Response.Redirect(url, false);
                
            }
        }
    }
}
